package com.shaoshaohuo.app.adapter;

import java.util.List;

import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.widget.ImageView;

/**
 * 广告viewpager的适配器
 *
 * @author YinSF
 * @createDate 2015-11-7
 */
public class AdPagerAdapter extends PagerAdapter {
    private List<ImageView> list;

    public AdPagerAdapter(List<ImageView> list) {
        super();
        this.list = list;
    }

    @Override
    public int getCount() {
        return Integer.MAX_VALUE;
    }

    @Override
    public boolean isViewFromObject(View arg0, Object arg1) {
        return arg0 == arg1;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
//        container.removeView(list.get(position % list.size()));
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        ImageView imageView = list.get(position% list.size());
        ViewGroup parent = (ViewGroup) imageView.getParent();
        if(parent!=null)
        parent.removeView(imageView);
        container.addView(imageView);
        return list.get(position % list.size());
    }

}
